package com.cangxuan.blockchain.controller;

import com.cangxuan.blockchain.bean.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class BaseController {

    HttpServletRequest request;
    HttpServletResponse response;

    @Autowired
    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }
    @Autowired
    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }

    protected Object success() {
        return new Result(200, "请求成功");
    }

    protected Object success(String message) {
        return new Result(200, message);
    }

    protected Object success(Object value) {
        return new Result(200, "请求成功", value);
    }

    protected Object success(String message, Object value) {
        return new Result(200, message, value);
    }

    protected Object fail(int code, String message) {
        response.setStatus(code);
        return new Result(code, message);
    }

}
